Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 472bf3cf7a
Fetching contributors…

Cannot retrieve contributors at this time

53 lines (40 sloc) 1.32 KB
#include <list>
#include <string.h>
#include "avarice.h"
#include "tcp.hh"
void TCPServer::initSocketAddress(struct sockaddr_in *name,
const char *hostname,
uint16_t port) {
struct hostent *hostInfo;
memset(name, 0, sizeof(*name));
name->sin_family = AF_INET;
name->sin_port = htons(port);
// Try numeric interpretation ( first, then
// hostname resolution if that failed.
if (inet_aton(hostname, &name->sin_addr) == 0) {
hostInfo = gethostbyname(hostname);
check(hostInfo != NULL, "Unknown host %s", hostname);
name->sin_addr = *(struct in_addr *)hostInfo->h_addr;
int TCPServer::makeSocket(struct sockaddr_in *name, uint16_t port)
int sock;
int tmp;
struct protoent *protoent;
sock = socket(PF_INET, SOCK_STREAM, 0);
// Allow rapid reuse of this port.
tmp = 1;
unixCheck(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&tmp, sizeof(tmp)));
// Enable TCP keep alive process.
tmp = 1;
unixCheck(setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&tmp, sizeof(tmp)));
unixCheck(bind(sock, (struct sockaddr *)name, sizeof(*name)));
protoent = getprotobyname("tcp");
check(protoent != NULL, "tcp protocol unknown (oops?)");
tmp = 1;
unixCheck(setsockopt(sock, protoent->p_proto, TCP_NODELAY,
(char *)&tmp, sizeof(tmp)));
return sock;
Jump to Line
Something went wrong with that request. Please try again.