Sat, 12 Nov 2005 16:55:47 +0000
[gaim-migrate @ 14349]
oops, didn't mean to commit that
| 2086 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains source for the ZSendPacket function. | |
| 3 | * | |
| 4 | * Created by: Robert French | |
| 5 | * | |
| 6 | * Copyright (c) 1987,1991 by the Massachusetts Institute of Technology. | |
| 7 | * For copying and distribution information, see the file | |
| 8 | * "mit-copyright.h". | |
| 9 | */ | |
| 10 | ||
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
11 | #include "internal.h" |
| 10867 | 12 | #ifdef WIN32 |
| 13 | #include <winsock.h> | |
| 14 | #else | |
| 2086 | 15 | #include <sys/socket.h> |
| 10867 | 16 | #endif |
| 2419 | 17 | static int wait_for_hmack(); |
| 2086 | 18 | |
| 19 | Code_t ZSendPacket(packet, len, waitforack) | |
| 20 | char *packet; | |
| 21 | int len; | |
| 22 | int waitforack; | |
| 23 | { | |
| 24 | Code_t retval; | |
| 25 | struct sockaddr_in dest; | |
| 26 | ZNotice_t notice, acknotice; | |
| 27 | ||
| 28 | if (!packet || len < 0) | |
| 29 | return (ZERR_ILLVAL); | |
| 30 | ||
| 31 | if (len > Z_MAXPKTLEN) | |
| 32 | return (ZERR_PKTLEN); | |
| 33 | ||
| 34 | if (ZGetFD() < 0) | |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
2419
diff
changeset
|
35 | if ((retval = ZOpenPort((unsigned short *)0)) != ZERR_NONE) |
| 2086 | 36 | return (retval); |
| 37 | ||
| 38 | dest = ZGetDestAddr(); | |
| 39 | ||
| 40 | if (sendto(ZGetFD(), packet, len, 0, (struct sockaddr *)&dest, | |
| 41 | sizeof(dest)) < 0) | |
| 42 | return (errno); | |
| 43 | ||
| 44 | if (!waitforack) | |
| 45 | return (ZERR_NONE); | |
| 46 | ||
| 47 | if ((retval = ZParseNotice(packet, len, ¬ice)) != ZERR_NONE) | |
| 48 | return (retval); | |
| 49 | ||
| 2419 | 50 | retval = Z_WaitForNotice (&acknotice, wait_for_hmack, ¬ice.z_uid, |
| 2086 | 51 | HM_TIMEOUT); |
| 52 | if (retval == ETIMEDOUT) | |
| 53 | return ZERR_HMDEAD; | |
| 54 | if (retval == ZERR_NONE) | |
| 55 | ZFreeNotice (&acknotice); | |
| 56 | return retval; | |
| 57 | } | |
| 58 | ||
| 2419 | 59 | static int wait_for_hmack(notice, uid) |
| 2086 | 60 | ZNotice_t *notice; |
| 61 | ZUnique_Id_t *uid; | |
| 62 | { | |
| 2419 | 63 | return (notice->z_kind == HMACK && ZCompareUID(¬ice->z_uid, uid)); |
| 2086 | 64 | } |