1 /* 2 * aprsc 3 * 4 * (c) Heikki Hannikainen, OH7LZB <hessu@hes.iki.fi> 5 * 6 * This program is licensed under the BSD license, which can be found 7 * in the file LICENSE. 8 * 9 */ 10 11 #include <stdio.h> 12 #include <string.h> 13 #include <netinet/in.h> 14 #include <arpa/inet.h> 15 #include <netdb.h> 16 17 #include "netlib.h" 18 19 #if 0 20 /* 21 * Convert address & port to string 22 */ 23 24 int aptoa(struct in_addr sin_addr, int sin_port, char *s, int len) 25 { 26 int l; 27 28 if (sin_addr.s_addr == INADDR_ANY) 29 return snprintf(s, len, "*:%d", sin_port); 30 else { 31 if (inet_ntop(AF_INET, (void *)&sin_addr, s, len) == NULL) { 32 return snprintf(s, len, "ERROR:%d", sin_port); 33 } else { 34 l = strlen(s); 35 return snprintf(s + l, len - l, ":%d", sin_port) + l; 36 } 37 } 38 } 39 40 /* 41 * Convert return values of gethostbyname() to a string 42 */ 43 44 int h_strerror(int i, char *s, int len) 45 { 46 switch (i) { 47 case HOST_NOT_FOUND: 48 return snprintf(s, len, "Host not found"); 49 case NO_ADDRESS: 50 return snprintf(s, len, "No IP address found for name"); 51 case NO_RECOVERY: 52 return snprintf(s, len, "A non-recovable name server error occurred"); 53 case TRY_AGAIN: 54 return snprintf(s, len, "A temporary error on an authoritative name server"); 55 default: 56 return snprintf(s, len, "%d", i); 57 } 58 } 59 #endif 60 61