4 * @brief UDP-Packet, contains data, sender and receiver
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 static status_t
destroy(packet_t
*this)
28 pfree(this->data
.ptr
);
34 * @brief helper function to set address used by set_dest & set_source
36 static status_t
set_addr(int family
, struct sockaddr
*saddr
, char *address
, u_int16_t port
)
43 struct sockaddr_in
*sin
= (struct sockaddr_in
*)saddr
;
44 sin
->sin_family
= AF_INET
;
45 sin
->sin_addr
.s_addr
= inet_addr("127.0.0.1");
46 sin
->sin_port
= htons(port
);
53 status_t
set_destination(packet_t
*this, char *address
, u_int16_t port
)
55 struct sockaddr
*saddr
= &(this->destination
);
56 return set_addr(this->family
, saddr
, address
, port
);
59 status_t
set_source(packet_t
*this, char *address
, u_int16_t port
)
61 struct sockaddr
*saddr
= &(this->source
);
62 return set_addr(this->family
, saddr
, address
, port
);
66 packet_t
*packet_create(int family
)
68 packet_t
*this = alloc_thing(packet_t
, "packet_t");
70 this->destroy
= destroy
;
71 this->set_destination
= set_destination
;
72 this->set_source
= set_source
;
74 this->family
= family
;
78 this->sockaddr_len
= sizeof(struct sockaddr_in
);
80 default: /* not supported */
86 this->data
.ptr
= NULL
;