rllib  1
rludpsocket.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                         rludpsocket.h  -  description
00003                              -------------------
00004     begin                : Tue Apr 03 2007
00005     copyright            : (C) 2007 by Rainer Lehrig
00006     email                : lehrig@t-online.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
00013  *   published by the Free Software Foundation                             *
00014  *                                                                         *
00015  ***************************************************************************/
00016 #ifndef _RL_UDP_SOCKET_H_
00017 #define _RL_UDP_SOCKET_H_
00018 
00019 #include "rldefine.h"
00020 #include "rlsocket.h"
00021 
00022 #ifdef RLWIN32
00023 #include <windows.h>
00024 #include <winsock.h>
00025 #include <io.h>
00026 #include <direct.h>
00027 #define  MSG_NOSIGNAL 0
00028 #else
00029 #include <sys/time.h>
00030 #include <sys/socket.h>
00031 #include <netinet/in.h>
00032 #include <arpa/inet.h>
00033 #include <netdb.h>
00034 #include "unistd.h"
00035 #endif
00036 
00040 class rlIpAdr
00041 {
00042 public:
00043   rlIpAdr();
00044   virtual ~rlIpAdr();
00045   int setAdr(const char *adr, int port);
00046   int operator== (rlIpAdr &address1);
00047   struct sockaddr_in address;
00048 };
00049 
00053 class rlUdpSocket
00054 {
00055 public:
00056   rlUdpSocket(int debug = 0);
00057   virtual ~rlUdpSocket();
00058 
00062   int setSockopt(int opt);
00063 
00067   int setSockopt(int level, int optname, void *optval, int optlen);
00068 
00072   int bind(int port);
00073 
00077   int select(int timeout);
00078 
00082   int recvfrom(void *buf, int maxlen, rlIpAdr *source, int timeout = -1);
00083 
00087   int sendto(const void *buf, int len, rlIpAdr *dest);
00088 
00092   int printf(rlIpAdr *dest, const char *format, ...);
00093 
00094   int debug, readflag, writeflag;
00095 
00096 private:
00097   struct sockaddr_in address;
00098   int s;
00099 };
00100 
00101 #endif