With the current code, we do have the following on a system where IPv6
is completely disabled:
socket(PF_INET6, SOCK_STREAM, IPPROTO_IP) = -1 EAFNOSUPPORT (Address
family not supported by protocol)
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(3, {sa_family=AF_INET6, sin6_port=htons(5002), inet_pton(AF_INET6,
"::", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = -1
EAFNOSUPPORT (Address family not supported by protocol)
The correct fix is to make a new call to getAddr() to ensure that the
entire struct addrinfo will be correctly filled out again with AF_INET
this time. This patch fixes.
40 lines
1.1 KiB
C
40 lines
1.1 KiB
C
/* Name: M. Andrew Webster
|
|
* Based on stevens networking book
|
|
* Description: function prototypes for socket library
|
|
*/
|
|
|
|
#ifndef _SOCKETLIB_H
|
|
#define _SOCKETLIB_H
|
|
|
|
#include <netdb.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <sys/time.h>
|
|
|
|
|
|
#define MAX_SIZE 8192
|
|
#define PORT 5002
|
|
#define RETRY_COUNT 7
|
|
#define SERVLEN 80
|
|
#define RETRY_DELAY 1000
|
|
|
|
#define ERROR -1
|
|
#define DEFAULT_IP "127.0.0.1"
|
|
#define DEFAULT_UNIX "/unix"
|
|
|
|
int setup_client(struct addrinfo *server_info);
|
|
int setup_server(struct addrinfo *server_address, int pPort);
|
|
int setupListenServer(struct addrinfo **pAddrInfo, int pPort);
|
|
int acceptClient(int pSock, struct addrinfo *server_addr);
|
|
void delay(long pMillisecs, struct timeval *pRes);
|
|
int getAddr(char *pHostname, char *pService, int pFamily, int pSockType, struct addrinfo **pAddrInfo);
|
|
|
|
// All calls to decode and encode need to be freed
|
|
char *decode_base64(unsigned char *input, int length, int *tActualLength);
|
|
// All calls to decode and encode need to be freed
|
|
char *encode_base64(unsigned char *input, int length);
|
|
|
|
|
|
#endif
|