sockets in Powerplant?
sockets in Powerplant?
- Subject: sockets in Powerplant?
- From: Marc Stibane <email@hidden>
- Date: Thu, 16 Oct 2003 15:30:40 +0200
I am carbonizing a PowerPlant app which itself was ported from Windows
years ago. The original app used WinSocks, and the guy who ported it
wrote some glue code to encapsulate these sockets into OpenTransport.
Well, bringing it to compile with Codewarrior Pro 9 was fairly easy -
just substitute all OpenTransport calls with their "InContext" - variant,
and since this is a standalone app, I did even set the context to NULL.
However, the code doesn't work. It should send UDP bradcasts to find our
RIP in the local subnet automatically (we'll bring that to Rendezvous
later this year), but a packet trace shows that nothing goes out to the
wire.
Of course, the MacOS 9 version runs fine.
Since the code thinks it uses sockets anyways, I want to remove the OT
glue layer and just use the sockets the OS provides.
Searching the whole Metrowerks folder for the text "socket" brought
several hits - but all of them in the Win32-X86 support folder. Bummer.
How do I use sockets from a Powerplant app? Which headers to include,
which libraries to link against? Where are the pitfalls?
Currently the project is CFM, but since it doesn't have to run under 9, I
could as well make it Mach-O.
The glue header looked like this:
>
#define MAXFD 32
>
>
typedef enum {
>
SockState_error = -1,
>
SockState_undefined = 0,
>
SockState_closed,
>
SockState_idle,
>
SockState_waitBind,
>
SockState_bindComplete,
>
SockState_waitOpen,
>
SockState_open,
>
SockState_waitData,
>
SockState_hasData,
>
SockState_waitConnect,
>
SockState_connected,
>
SockState_waitDisconnect,
>
SockState_disconnected
>
} SockState;
>
>
typedef struct {
>
EndpointRef ep;
>
TEndpointInfo info;
>
TCall call;
>
OSStatus err;
>
SockState state;
>
TUDErr UDPErr;
>
bool bound;
>
} SockRec;
>
>
typedef bool fd_set[MAXFD];
>
>
extern void FD_SET(int fd, fd_set *fdset);
>
extern void FD_CLR(int fd, fd_set *fdset);
>
extern int FD_ISSET(int fd, fd_set *fdset);
>
extern void FD_ZERO(fd_set *fdset);
>
>
typedef int SOCKET;
>
#define INVALID_SOCKET -1
>
extern int send(SOCKET s, const char *buf, size_t len, int flags);
>
extern int recv(SOCKET s, void *buf, size_t len, int flags);
>
extern BOOL shutdown(SOCKET x, int flags);
>
extern BOOL closesocket(SOCKET x);
>
extern ULONG inet_addr(const char * dot_notation);
>
extern SOCKET socket(int domain, int type, int protocol);
>
extern int connect(SOCKET, const struct sockaddr*, int);
>
extern int select(SOCKET, fd_set*, fd_set*, fd_set*, struct timeval *);
>
>
extern int sendto(SOCKET s, char *msg, int len, int flags, struct sockaddr
>
*to, int tolen);
>
extern int recvfrom(SOCKET s, char *buf, int len, int flags, struct
>
sockaddr *from, int *fromlen);
>
extern int setsockopt(SOCKET s, int level, int optname, const char
>
*optval, int optlen);
>
extern int bind(SOCKET s, struct sockaddr *, int);
>
extern int ioctlsocket(SOCKET s, int what, void *ioParams);
>
extern int WSAGetLastError();
>
>
typedef struct sockaddr {
>
unsigned short sa_family;
>
char sa_data[14];
>
} SOCKADDR;
>
>
struct sockaddr_in {
>
unsigned short sin_family;
>
int sin_port;
>
union {
>
unsigned long s_addr;
>
} sin_addr;
>
};
>
>
>
#define SD_BOTH 3
>
#define SD_SEND 1
>
#define SOCK_STREAM 2
>
#define SOCK_DGRAM 1
>
#define IPPROTO_TCP 1
>
#define SOCKET_ERROR -1
>
>
#define SO_DEBUG 0x0001
>
#define SO_ACCEPTCONN 0x0002
>
#define SO_REUSEADDR 0x0004
>
#define SO_KEEPALIVE 0x0008
>
#define SO_DONTROUTE 0x0010
>
#define SO_BROADCAST 0x0020
>
#define SO_USELOOPBACK 0x0040
>
#define SO_LINGER 0x0080
>
#define SO_OOBINLINE 0x0100
>
>
#define SOL_SOCKET 0xffff
>
>
#define INADDR_ANY (UInt32)0x00000000
>
#define INADDR_LOOPBACK 0x7f000001
>
#define INADDR_BROADCAST (UInt32)0xffffffff
>
#define INADDR_NONE 0xffffffff
>
>
#define FIONBIO 0x0001
>
>
#define WSAEWOULDBLOCK -99
>
>
#define ntohs(x) (x)
>
#define htons(x) (x)
>
#define htonl(x) (x)
>
#define ntohl(x) (x)
>
#define Sleep(n)
>
extern BOOL gOTInited;
Marc Stibane
Fesh! email@hidden
Kurf|rstenstr. 154 tel +49-30-3990 2690
10785 Berlin, Germany mobil +49-173-6522 422
In a world without walls and fences,
who needs windows and gates?
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.