summaryrefslogtreecommitdiffabout
path: root/pumpkin/StringsAttached.m
authorMichael Krelin <hacker@klever.net>2012-12-08 21:19:17 (UTC)
committer Michael Krelin <hacker@klever.net>2012-12-11 21:59:29 (UTC)
commit8808689fe340bec6e90ab13dd502292b0579cf1f (patch) (unidiff)
tree45b7c863151341f687b74e40bffcbd7ab5468783 /pumpkin/StringsAttached.m
parent6e7e413ca364d79673e523c09767c18e7cff1bec (diff)
downloadpumpkin-osx/0.0.zip
pumpkin-osx/0.0.tar.gz
pumpkin-osx/0.0.tar.bz2
initial osx portosx/0.0
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'pumpkin/StringsAttached.m') (more/less context) (ignore whitespace changes)
-rw-r--r--pumpkin/StringsAttached.m19
1 files changed, 19 insertions, 0 deletions
diff --git a/pumpkin/StringsAttached.m b/pumpkin/StringsAttached.m
new file mode 100644
index 0000000..8ad5868
--- a/dev/null
+++ b/pumpkin/StringsAttached.m
@@ -0,0 +1,19 @@
1
2#import "StringsAttached.h"
3#include <arpa/inet.h>
4
5@implementation NSString (StringsAttached)
6
7+ stringWithSocketAddress:(const struct sockaddr_in*)sin {
8 return [NSString stringWithFormat:@"%@:%u",[NSString stringWithHostAddress:sin],ntohs(sin->sin_port)];
9}
10+ stringWithHostAddress:(const struct sockaddr_in*)sin {
11 char tmp[32];
12 addr2ascii(sin->sin_family,&sin->sin_addr,sizeof(sin->sin_addr),tmp);
13 return @(tmp);
14}
15+ (id)stringWithPortNumber:(const struct sockaddr_in *)sin {
16 return [NSString stringWithFormat:@"%u",ntohs(sin->sin_port)];
17}
18
19@end