Converting ascii hex values to hex bytes
Kevin B. Kenny KE9TV
kkenny at wind.nrtc.northrop.com
Thu Oct 25 02:52:52 AEST 1990
In article <298 at cti1.UUCP> mpledger at cti1.UUCP (Mark Pledger) writes:
>What I want to do is to be able to convert 122.10.10.44 into a
>character string of 4 bytes that equals "\x7a\x0a\x0a\x2c". How can
>I convert the ascii representation into hex? I tried using itoa(),
>but the result is in ascii character format
If you're on a 4.x BSD machine, or another one that has the `inet'
library, the accepted way to parse Internet addresses is:
----------------------------------------
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
...
char * address_in_dotted_form;
unsigned long parsed_address;
...
parsed_address = inet_addr (address_in_dotted_form);
----------------------------------------
The manual page for this is inet(3n).
Kevin, KE9TV
More information about the Comp.lang.c
mailing list