summaryrefslogtreecommitdiffabout
path: root/pumpkin/StringsAttached.m
Unidiff
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