2 * A quick little implementation of the makensap function of the
3 * xtimosi package. It's needed to make the demo apps work.
9 #include <sys/socket.h>
10 #include <netinet/in.h>
11 #include <arpa/inet.h>
16 static struct sockaddr_in *tcpip_strtoaddr(const char *str);
19 * text format is <hostname> | <IP-address> ':' <port>. No spaces.
20 * The binary form is a struct sockaddr_ip.
22 int makensap(char *text, unsigned char *binary)
24 struct sockaddr_in *addr;
26 fprintf(stderr, "Mapping textform NSAP '%s'\n", text);
27 if (!(addr = tcpip_strtoaddr(text)))
29 fprintf(stderr, "Failed to resolve '%s'\n", text);
32 memcpy(binary, addr, sizeof(struct sockaddr_in));
33 return sizeof(struct sockaddr_in);
37 * This is the address mapper from the comstack submodule of YAZ.
39 static struct sockaddr_in *tcpip_strtoaddr(const char *str)
41 static struct sockaddr_in add;
47 add.sin_family = AF_INET;
49 if ((p = strchr(buf, ':')))
54 add.sin_port = htons(port);
55 if ((hp = gethostbyname(buf)))
56 memcpy(&add.sin_addr.s_addr, *hp->h_addr_list, sizeof(struct in_addr));
57 else if ((tmpadd = inet_addr(buf)) != 0)
58 memcpy(&add.sin_addr.s_addr, &tmpadd, sizeof(struct in_addr));