2 * Copyright (c) 2005, Swedish Institute of Computer Science
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * This file is part of the Contiki operating system.
31 * @(#)$Id: codeprop.c,v 1.5 2010/10/19 18:29:05 adamdunkels Exp $
38 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <sys/types.h>
43 #include <netinet/in.h>
46 #include <sys/types.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
51 /* Should be included from codeprop.h, but the include paths in the makefiles
52 isn't set up for that. */
56 main(int argc
, char **argv
) {
57 struct sockaddr_in sa
;
63 printf("usage: %s ipaddress filename\n", argv
[0]);
70 if((s
= socket(AF_INET
,SOCK_STREAM
,0)) < 0){
71 perror("Can't create socket");
75 /* Set the destination address of the socket. */
76 bzero((char *) &sa
, sizeof(sa
));
77 sa
.sin_family
= AF_INET
;
78 sa
.sin_addr
.s_addr
= inet_addr(ip_addr
);
79 sa
.sin_port
= uip_htons(port
);
81 /* Connect the socket to the remote host. */
82 if(connect(s
, (struct sockaddr
*)&sa
, sizeof(sa
)) < 0) {
83 perror("connect failed");
86 socklen_t slen
= 576 - 40;
87 if (setsockopt(s
, SOL_SOCKET
, SO_SNDBUF
, &slen
, sizeof(slen
)) < 0) {
88 perror("setsockopt failed");
92 if((fd
= open(argv
[2], O_RDONLY
)) < 0) {
93 perror("Could not open file");
102 len
= read(fd
, &buf
[HDR_SIZE
], sizeof(buf
) - HDR_SIZE
);
104 printf("File successfully sent (%d bytes)\n", total
);
105 len
= read(s
, buf
, sizeof(buf
));
107 printf("Reply: %s", buf
);
108 if(buf
[0] != 'o' || buf
[1] != 'k') {
109 /* Cut and pasted from core/loader/elfloader.h */
116 "UNKNOWN_SEGMENT 6\n"
121 "MULTIPLY_DEFINED 11\n");
128 if(write(s
, buf
, len
+ HDR_SIZE
) == -1) {
129 perror("network send failed");