Sat, 25 Jun 2005 17:58:42 +0000
[gaim-migrate @ 12905]
I use
CFLAGS="-g3 -D_FORTIFY_SOURCE=2 -Werror-implicit-function-declaration -Wno-pointer-sign -Wdeclaration-after-statement"
... shouldn't I be using Gentoo ?
| 2086 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains source for the ZInitialize function. | |
| 3 | * | |
| 4 | * Created by: Robert French | |
| 5 | * | |
| 6 | * $Source$ | |
| 10867 | 7 | * $Author: thekingant $ |
| 2086 | 8 | * |
| 9 | * Copyright (c) 1987, 1991 by the Massachusetts Institute of Technology. | |
| 10 | * For copying and distribution information, see the file | |
| 11 | * "mit-copyright.h". | |
| 12 | */ | |
| 13 | /* $Header$ */ | |
| 14 | ||
| 15 | #ifndef lint | |
| 16 | static char rcsid_ZInitialize_c[] = | |
| 17 | "$Zephyr: /afs/athena.mit.edu/astaff/project/zephyr/src/lib/RCS/ZInitialize.c,v 1.17 89/05/30 18:11:25 jtkohl Exp $"; | |
| 18 | #endif | |
| 19 | ||
| 10867 | 20 | #ifdef ZEPHYR_USES_KERBEROS |
| 21 | #ifdef WIN32 | |
| 22 | ||
| 23 | #else | |
| 24 | #include <krb_err.h> | |
| 25 | #endif | |
| 26 | #endif | |
| 27 | ||
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
2419
diff
changeset
|
28 | #include "internal.h" |
| 2086 | 29 | |
| 10867 | 30 | #ifdef WIN32 |
| 31 | #include <winsock2.h> | |
| 32 | #else | |
| 2086 | 33 | #include <sys/socket.h> |
| 34 | #endif | |
| 35 | ||
| 10867 | 36 | |
| 2419 | 37 | #ifndef INADDR_NONE |
| 38 | #define INADDR_NONE 0xffffffff | |
| 39 | #endif | |
| 40 | ||
| 2086 | 41 | Code_t ZInitialize() |
| 42 | { | |
| 43 | struct servent *hmserv; | |
| 2419 | 44 | struct hostent *hostent; |
| 45 | char addr[4], hostname[MAXHOSTNAMELEN]; | |
| 46 | struct in_addr servaddr; | |
| 47 | struct sockaddr_in sin; | |
| 48 | int s, sinsize = sizeof(sin); | |
| 49 | Code_t code; | |
| 50 | ZNotice_t notice; | |
| 2086 | 51 | #ifdef ZEPHYR_USES_KERBEROS |
| 2419 | 52 | char *krealm = NULL; |
| 2086 | 53 | int krbval; |
| 2419 | 54 | char d1[ANAME_SZ], d2[INST_SZ]; |
| 2086 | 55 | |
| 10867 | 56 | /* initialize_krb_error_table(); */ |
| 2086 | 57 | #endif |
| 58 | ||
| 59 | initialize_zeph_error_table(); | |
| 60 | ||
| 61 | (void) memset((char *)&__HM_addr, 0, sizeof(__HM_addr)); | |
| 62 | ||
| 63 | __HM_addr.sin_family = AF_INET; | |
| 64 | ||
| 65 | /* Set up local loopback address for HostManager */ | |
| 66 | addr[0] = 127; | |
| 67 | addr[1] = 0; | |
| 68 | addr[2] = 0; | |
| 69 | addr[3] = 1; | |
| 70 | ||
| 71 | hmserv = (struct servent *)getservbyname(HM_SVCNAME, "udp"); | |
| 72 | __HM_addr.sin_port = (hmserv) ? hmserv->s_port : HM_SVC_FALLBACK; | |
| 73 | ||
| 74 | (void) memcpy((char *)&__HM_addr.sin_addr, addr, 4); | |
| 75 | ||
| 76 | __HM_set = 0; | |
| 77 | ||
| 2419 | 78 | /* Initialize the input queue */ |
| 79 | __Q_Tail = NULL; | |
| 80 | __Q_Head = NULL; | |
| 81 | ||
| 82 | /* if the application is a server, there might not be a zhm. The | |
| 83 | code will fall back to something which might not be "right", | |
| 84 | but this is is ok, since none of the servers call krb_rd_req. */ | |
| 85 | ||
| 86 | servaddr.s_addr = INADDR_NONE; | |
| 87 | if (! __Zephyr_server) { | |
| 88 | if ((code = ZOpenPort(NULL)) != ZERR_NONE) | |
| 89 | return(code); | |
| 90 | ||
| 91 | if ((code = ZhmStat(NULL, ¬ice)) != ZERR_NONE) | |
| 92 | return(code); | |
| 93 | ||
| 94 | ZClosePort(); | |
| 95 | ||
| 96 | /* the first field, which is NUL-terminated, is the server name. | |
| 97 | If this code ever support a multiplexing zhm, this will have to | |
| 98 | be made smarter, and probably per-message */ | |
| 99 | ||
| 2086 | 100 | #ifdef ZEPHYR_USES_KERBEROS |
| 2419 | 101 | krealm = krb_realmofhost(notice.z_message); |
| 102 | #endif | |
| 103 | hostent = gethostbyname(notice.z_message); | |
| 104 | if (hostent && hostent->h_addrtype == AF_INET) | |
| 105 | memcpy(&servaddr, hostent->h_addr, sizeof(servaddr)); | |
| 106 | ||
| 107 | ZFreeNotice(¬ice); | |
| 108 | } | |
| 109 | ||
| 110 | #ifdef ZEPHYR_USES_KERBEROS | |
| 111 | if (krealm) { | |
| 112 | strcpy(__Zephyr_realm, krealm); | |
| 113 | } else if ((krb_get_tf_fullname(TKT_FILE, d1, d2, __Zephyr_realm) | |
| 114 | != KSUCCESS) && | |
| 115 | ((krbval = krb_get_lrealm(__Zephyr_realm, 1)) != KSUCCESS)) { | |
| 2086 | 116 | return (krbval); |
| 2419 | 117 | } |
| 118 | #else | |
| 119 | strcpy(__Zephyr_realm, "local-realm"); | |
| 2086 | 120 | #endif |
| 121 | ||
| 2419 | 122 | __My_addr.s_addr = INADDR_NONE; |
| 123 | if (servaddr.s_addr != INADDR_NONE) { | |
| 124 | /* Try to get the local interface address by connecting a UDP | |
| 125 | * socket to the server address and getting the local address. | |
| 126 | * Some broken operating systems (e.g. Solaris 2.0-2.5) yield | |
| 127 | * INADDR_ANY (zero), so we have to check for that. */ | |
| 128 | s = socket(AF_INET, SOCK_DGRAM, 0); | |
| 129 | if (s != -1) { | |
| 130 | memset(&sin, 0, sizeof(sin)); | |
| 131 | sin.sin_family = AF_INET; | |
| 132 | memcpy(&sin.sin_addr, &servaddr, sizeof(servaddr)); | |
| 133 | sin.sin_port = HM_SRV_SVC_FALLBACK; | |
| 134 | if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) == 0 | |
| 135 | && getsockname(s, (struct sockaddr *) &sin, &sinsize) == 0 | |
| 136 | && sin.sin_addr.s_addr != 0) | |
| 137 | memcpy(&__My_addr, &sin.sin_addr, sizeof(__My_addr)); | |
| 138 | close(s); | |
| 139 | } | |
| 140 | } | |
| 141 | if (__My_addr.s_addr == INADDR_NONE) { | |
| 142 | /* We couldn't figure out the local interface address by the | |
| 143 | * above method. Try by resolving the local hostname. (This | |
| 144 | * is a pretty broken thing to do, and unfortunately what we | |
| 145 | * always do on server machines.) */ | |
| 146 | if (gethostname(hostname, sizeof(hostname)) == 0) { | |
| 147 | hostent = gethostbyname(hostname); | |
| 148 | if (hostent && hostent->h_addrtype == AF_INET) | |
| 149 | memcpy(&__My_addr, hostent->h_addr, sizeof(__My_addr)); | |
| 150 | } | |
| 151 | } | |
| 152 | /* If the above methods failed, zero out __My_addr so things will | |
| 153 | * sort of kind of work. */ | |
| 154 | if (__My_addr.s_addr == INADDR_NONE) | |
| 155 | __My_addr.s_addr = 0; | |
| 156 | ||
| 2086 | 157 | /* Get the sender so we can cache it */ |
| 158 | (void) ZGetSender(); | |
| 159 | ||
| 160 | return (ZERR_NONE); | |
| 161 | } | |
| 2419 | 162 |