1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/*
* $Id: pilot-install-netsync.c,v 1.49 2007/06/01 01:13:55 desrod Exp $
*
* pilot-install-netsync.c: Palm Network Information Installer
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "pi-dlp.h"
#include "pi-header.h"
#include "pi-userland.h"
poptContext po;
int main(int argc, char *argv[])
{
int enable = -1,
sd = -1,
po_err = -1;
const char
*hostname = NULL,
*address = NULL,
*netmask = NULL;
const struct poptOption options[] = {
USERLAND_RESERVED_OPTIONS
{ "enable", 'e', POPT_ARG_VAL, &enable, 1, "Enables LANSync on the Palm"},
{ "disable", 'd', POPT_ARG_VAL, &enable, 0, "Disable the LANSync setting on the Palm"},
{ "name", 'n', POPT_ARG_STRING, &hostname, 0, "The hostname of the remote machine you sync with", "<name>"},
{ "address", 'a', POPT_ARG_STRING, &address, 0, "IP address of the remote machine you connect to", "<address>"},
{ "mask", 'm', POPT_ARG_STRING, &netmask, 0, "Subnet mask of the network your Palm is on", "<netmask>"},
POPT_TABLEEND
};
struct NetSyncInfo Net;
struct in_addr addr;
po = poptGetContext("pilot-install-netsync", argc, (const char **) argv, options, 0);
poptSetOtherOptionHelp(po," [-p port] <netsync options>\n\n"
" Assigns your Palm device NetSync information\n\n"
" Example:\n"
" -p usb: -e -n \"NEPTUNE\" -a 10.0.1.10 -m 255.255.255.0\n\n");
if (argc < 2) {
poptPrintUsage(po,stderr,0);
return 1;
}
while ((po_err = poptGetNextOpt(po)) >= 0) {
}
if (po_err < -1) plu_badoption(po,po_err);
/* FIXME: Take the user-supplied IP or hostname and reverse it to
get the other component, which reduces the complexity of this by
one argument passed in. getnameinfo() will help here. */
if (address && !inet_pton(AF_INET, address, &addr)) {
fprintf(stderr," ERROR: The address you supplied, '%s' is in invalid.\n"
" Please supply a dotted quad, such as 1.2.3.4\n\n", address);
return 1;
}
if (netmask && !inet_pton(AF_INET, netmask, &addr)) {
fprintf(stderr," ERROR: The netmask you supplied, '%s' is in invalid.\n"
" Please supply a dotted quad, such as 255.255.255.0\n\n", netmask);
return 1;
}
sd = plu_connect();
if (sd < 0)
goto error;
if (dlp_OpenConduit(sd) < 0)
goto error_close;
/* Read and write the LANSync data to the Palm device */
if (dlp_ReadNetSyncInfo(sd, &Net) < 0)
goto error_close;
if (enable != -1)
Net.lanSync = enable;
if (!plu_quiet) {
printf(" LANSync....: %sabled\n", (Net.lanSync == 1 ? "En" : "Dis"));
fflush(stdout);
}
if (hostname)
strncpy(Net.hostName, hostname, sizeof(Net.hostName));
if (address)
strncpy(Net.hostAddress, address, sizeof(Net.hostAddress));
if (netmask)
strncpy(Net.hostSubnetMask, netmask,
sizeof(Net.hostSubnetMask));
if (!plu_quiet) {
printf(" Hostname...: %s\n", Net.hostName);
printf(" IP Address.: %s\n", Net.hostAddress);
printf(" Netmask....: %s\n\n", Net.hostSubnetMask);
}
if (dlp_WriteNetSyncInfo(sd, &Net) < 0)
goto error_close;
if (dlp_AddSyncLogEntry(sd, "pilot-install-netsync, exited normally.\n"
"Thank you for using pilot-link.\n") < 0)
goto error_close;
if (dlp_EndOfSync(sd, 0) < 0)
goto error_close;
if (pi_close(sd) < 0)
goto error;
return 0;
error_close:
pi_close(sd);
error:
return -1;
}
/* vi: set ts=8 sw=4 sts=4 noexpandtab: cin */
/* ex: set tabstop=4 expandtab: */
/* Local Variables: */
/* indent-tabs-mode: t */
/* c-basic-offset: 8 */
/* End: */
|