W
wright.brandt
I am new to programming in C. If my question is not appropriate for
this newsgroup I apologize. I Have been tasked with writing a small
application to do some back end processing in C and have had little
trouble getting most of the app written. What seems to be holding me up
is a tricky (at least for me) piece of network address logic. I need to
be able to take an ip address and compare it to a subnet represented
in the doted and slashed notation ( 192.168.0.0/24 ) and determine if
that ip address is within the subnet. I have played around with some of
the functions defined in netinet/in.b and arpa/inet.h but have not been
able to get anything to work. The code below (kind of) demonstrates
what I need to do but not how to do it (ofcourse, or I wouldnt need
help right ;0 ). I have to believe that this would be a no-brainer for
someone who is familiar with C and basic networking. I am sure there is
a built in function or common snippet that will do it. I just do not
know about it. Any help anyone could give me would be greatly
appreciated! Thanks in advance.
char * sAddress = "192.168.0.1";
char * sSubnet = "192.168.0.0/24";
if ( address_is_in_subnet(sAddress, sSubnet) ){
...
...
...
}
-- (e-mail address removed)
this newsgroup I apologize. I Have been tasked with writing a small
application to do some back end processing in C and have had little
trouble getting most of the app written. What seems to be holding me up
is a tricky (at least for me) piece of network address logic. I need to
be able to take an ip address and compare it to a subnet represented
in the doted and slashed notation ( 192.168.0.0/24 ) and determine if
that ip address is within the subnet. I have played around with some of
the functions defined in netinet/in.b and arpa/inet.h but have not been
able to get anything to work. The code below (kind of) demonstrates
what I need to do but not how to do it (ofcourse, or I wouldnt need
help right ;0 ). I have to believe that this would be a no-brainer for
someone who is familiar with C and basic networking. I am sure there is
a built in function or common snippet that will do it. I just do not
know about it. Any help anyone could give me would be greatly
appreciated! Thanks in advance.
char * sAddress = "192.168.0.1";
char * sSubnet = "192.168.0.0/24";
if ( address_is_in_subnet(sAddress, sSubnet) ){
...
...
...
}
-- (e-mail address removed)