/*
* FILE: net_udp.c
* AUTHOR: Colin Perkins
* MODIFIED: Orion Hodson, Piers O'Hanlon, Kristian Hasler
*
* Copyright (c) 1998-2000 University College London
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Science
* Department at University College London
* 4. Neither the name of the University nor of the Department may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* If this machine supports IPv6 the symbol HAVE_IPv6 should */
/* be defined in either config_unix.h or config_win32.h. The */
/* appropriate system header files should also be included */
/* by those files. */
#include "net_udp.h"
#define UNUSED(x) (x=x)
#define IPv4 4
#define IPv6 6
#ifdef WIN2K_IPV6
const struct in6_addr in6addr_any = {IN6ADDR_ANY_INIT};
#endif
#ifdef WINXP_IPV6
const struct in6_addr in6addr_any = {IN6ADDR_ANY_INIT};
#endif
/* This is pretty nasty but it's the simplest way to get round */
/* the Detexis bug that means their MUSICA IPv6 stack uses */
/* IPPROTO_IP instead of IPPROTO_IPV6 in setsockopt calls */
/* We also need to define in6addr_any */
#ifdef MUSICA_IPV6
#define IPPROTO_IPV6 IPPROTO_IP
struct in6_addr in6addr_any = {IN6ADDR_ANY_INIT};
/* These DEF's are required as MUSICA's winsock6.h causes a clash with some of the
* standard ws2tcpip.h definitions (eg struct in_addr6).
* Note: winsock6.h defines AF_INET6 as 24 NOT 23 as in winsock2.h - I have left it
* set to the MUSICA value as this is used in some of their function calls.
*/
//#define AF_INET6 23
#define IP_MULTICAST_LOOP 11 /*set/get IP multicast loopback */
#define IP_MULTICAST_IF 9 /* set/get IP multicast i/f */
#define IP_MULTICAST_TTL 10 /* set/get IP multicast ttl */
#define IP_MULTICAST_LOOP 11 /*set/get IP multicast loopback */
#define IP_ADD_MEMBERSHIP 12 /* add an IP group membership */
#define IP_DROP_MEMBERSHIP 13/* drop an IP group membership */
#define IN6_IS_ADDR_UNSPECIFIED(a) (((a)->s6_addr32[0] == 0) && \
((a)->s6_addr32[1] == 0) && \
((a)->s6_addr32[2] == 0) && \
((a)->s6_addr32[3] == 0))
struct ip_mreq {
struct in_addr imr_multiaddr; /* IP multicast address of group */
struct in_addr imr_interface; /* local IP address of interface */
};
#endif
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif
#ifdef WIN32
/* Want to use both Winsock 1 and 2 socket options, but since
* IPv6 support requires Winsock 2 we have to add own backwards
* compatibility for Winsock 1.
*/
#define SETSOCKOPT winsock_versions_setsockopt
#else
#define SETSOCKOPT setsockopt
#endif /* WIN32 */
/*****************************************************************************/
/* Support functions... */
/*****************************************************************************/
static void
socket_error(const char *msg, ...)
{
char buffer[255];
uint32_t blen = sizeof(buffer) / sizeof(buffer[0]);
va_list ap;
#ifdef WIN32
#define WSERR(x) {#x,x}
struct wse {
char errname[20];
int my_errno;
};
struct wse ws_errs[] = {
WSERR(WSANOTINITIALISED), WSERR(WSAENETDOWN), WSERR(WSAEACCES),
WSERR(WSAEINVAL), WSERR(WSAEINTR), WSERR(WSAEINPROGRESS),
WSERR(WSAEFAULT), WSERR(WSAENETRESET), WSERR(WSAENOBUFS),
WSERR(WSAENOTCONN), WSERR(WSAENOTSOCK), WSERR(WSAEOPNOTSUPP),
WSERR(WSAESHUTDOWN), WSERR(WSAEWOULDBLOCK), WSERR(WSAEMSGSIZE),
WSERR(WSAEHOSTUNREACH), WSERR(WSAECONNABORTED), WSERR(WSAECONNRESET),
WSERR(WSAEADDRNOTAVAIL), WSERR(WSAEAFNOSUPPORT), WSERR(WSAEDESTADDRREQ),
WSERR(WSAENETUNREACH), WSERR(WSAETIMEDOUT), WSERR(0)
};
int i, e = WSAGetLastError();
i = 0;
while(ws_errs[i].my_errno && ws_errs[i].my_errno != e) {
i++;
}
va_start(ap, msg);
_vsnprintf(buffer, blen, msg, ap);
va_end(ap);
printf("ERROR: %s, (%d - %s)\n", msg, e, ws_errs[i].errname);
#else
va_start(ap, msg);
vsnprintf(buffer, blen, msg, ap);
va_end(ap);
perror(buffer);
#endif
}
#ifdef WIN32
/* ws2tcpip.h defines these constants with different values from
* winsock.h so files that use winsock 2 values but try to use
* winsock 1 fail. So what was the motivation in changing the
* constants ?
*/
#define WS1_IP_MULTICAST_IF 2 /* set/get IP multicast interface */
#define WS1_IP_MULTICAST_TTL 3 /* set/get IP multicast timetolive */
#define WS1_IP_MULTICAST_LOOP 4 /* set/get IP multicast loopback */
#define WS1_IP_ADD_MEMBERSHIP 5 /* add an IP group membership */
#define WS1_IP_DROP_MEMBERSHIP 6 /* drop an IP group membership */
/* winsock_versions_setsockopt tries 1 winsock version of option
* optname and then winsock 2 version if that failed.
* note: setting the TTL never fails, so we have to try both.
*/
static int
winsock_versions_setsockopt(SOCKET s, int level, int optname, const char FAR * optval, int optlen)
{
int success = -1;
switch (optname) {
case IP_MULTICAST_IF:
success = setsockopt(s, level, WS1_IP_MULTICAST_IF, optval, optlen);
break;
case IP_MULTICAST_TTL:
success = setsockopt(s, level, WS1_IP_MULTICAST_TTL, optval, optlen);
success = setsockopt(s, level, optname, optval, optlen);
break;
case IP_MULTICAST_LOOP:
success = setsockopt(s, level, WS1_IP_MULTICAST_LOOP, optval, optlen);
break;
case IP_ADD_MEMBERSHIP:
success = setsockopt(s, level, WS1_IP_ADD_MEMBERSHIP, optval, optlen);
break;
case IP_DROP_MEMBERSHIP:
success = setsockopt(s, level, WS1_IP_DROP_MEMBERSHIP, optval, optlen);
break;
}
if (success != -1) {
return success;
}
return setsockopt(s, level, optname, optval, optlen);
}
#endif
#ifdef NEED_INET_ATON
#ifdef NEED_INET_ATON_STATIC
static
#endif
int inet_aton(const char *name, struct in_addr *addr)
{
addr->s_addr = inet_addr(name);
return (addr->s_addr != (in_addr_t) INADDR_NONE);
}
#endif
#ifdef NEED_IN6_IS_ADDR_MULTICAST
#define IN6_IS_ADDR_MULTICAST(addr) ((addr)->s6_addr[0] == 0xffU)
#endif
#if defined(NEED_IN6_IS_ADDR_UNSPECIFIED) && defined(MUSICA_IPV6)
#define IN6_IS_ADDR_UNSPECIFIED(addr) IS_UNSPEC_IN6_ADDR(*addr)
#endif
/*****************************************************************************/
/* IPv4 specific functions... */
/*****************************************************************************/
BOOL udp_addr_valid4(const char *dst)
{
struct in_addr addr4;
struct hostent *h;
if
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
IVTlinux.rar (53个子文件)
IVTlinux
uart
Makefile 17B
uart.c 13KB
Makefile 947B
voice
Makefile 0B
Makefile.build 636B
log
Makefile 16B
log.c 6KB
gps
Makefile 40B
gps.c 4KB
gps_analyse.c 4KB
tools
watchdog.c 1KB
stime.c 1KB
Makefile 92B
supervisorRegister.c 4KB
utils.c 14KB
network
Makefile 84B
net.c 13KB
net_tcp.c 10KB
net_udp.c 25KB
net_local.c 5KB
primary
Makefile 20B
primary.c 8KB
include
common.h 5KB
net_tcp.h 2KB
glabtypes.h 884B
uart.h 2KB
net_local.h 1KB
iniConfigFile.h 913B
stime.h 891B
video.h 206B
net.h 2KB
config.h 3KB
supervisorRegister.h 414B
watchdog.h 599B
utils.h 2KB
sharemem.h 207B
log.h 478B
net_udp.h 3KB
camera.h 1KB
primary.h 795B
gps_analyse.h 165B
gps.h 1KB
timer.h 1KB
config
Makefile 45B
config.c 1KB
iniConfigFile.c 7KB
main.c 3KB
timer
Makefile 18B
timer.c 13KB
video
Makefile 60B
camera.c 7KB
video.c 2KB
sharemem.c 2KB
共 53 条
- 1
MINGTING1323
- 粉丝: 69
- 资源: 29
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页