csbind.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
*/
#include "cslib.h"
/*
* low level for csbind()
*/
static int
{
#if CS_LIB_V10
int fd;
{
if (!addr)
{
return fd;
}
return fd;
}
{
{
return -1;
}
{
return fd;
}
}
#else
#if CS_LIB_SOCKET
int fd;
int sock;
int r;
struct sockaddr_in nam;
else
{
return -1;
}
{
return -1;
}
if (addr)
{
#if defined(O_NONBLOCK) || defined(FNDELAY)
int fl;
#endif
#if defined(IPPROTO_TCP) && defined(TCP_NODELAY)
int sl;
#endif
{
#if defined(O_NONBLOCK) || defined(FNDELAY)
#if defined(FNDELAY)
#else
#endif
#endif
#if defined(IPPROTO_TCP) && defined(TCP_NODELAY)
if (sock == SOCK_STREAM)
{
sl = 1;
}
#endif
}
#ifdef EINPROGRESS
|| errno == EINPROGRESS
#endif
)
{
{
#if defined(O_NONBLOCK) || defined(FNDELAY)
if (fl != -1)
#endif
#if defined(IPPROTO_TCP) && defined(TCP_NODELAY)
if (sock == SOCK_STREAM)
{
sl = 0;
}
#endif
}
return fd;
}
}
else
{
#ifdef SO_REUSEADDR
{
int n = 1;
}
#endif
{
{
}
return fd;
}
}
#else
#endif
#endif
return -1;
}
/*
* create [addr==0] or open stream fd for <type,addr,port>
* for create
*
* addr CS_LOCAL for local address
*
* port CS_PORT_NORMAL for normal port allocation
* CS_PORT_RESERVED for reserved port allocation
*/
int
csbind(register Cs_t* state, const char* type, unsigned long addr, unsigned long port, unsigned long clone)
{
int fd;
if (port == CS_PORT_INVALID)
return -1;
if (port == CS_PORT_RESERVED)
{
static unsigned int last = IPPORT_RESERVED;
if (addr)
{
return -1;
}
do
{
{
break;
}
goto ok;
return -1;
}
{
return -1;
}
return -1;
if (clone)
{
int n;
char buf[16];
}
ok:
messagef((state->id, NiL, -8, "bind(%s,%s,%u,%lu) = %d", type, csntoa(state, addr), port, clone, fd));
return fd;
}
int
{
}