"例 9090ポートを開いているプロセスを表示"
lsof -i 9090
#import <Foundation/Foundation.h> #import <stdio.h> int main(void) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; NSObject *obj = [[NSObject alloc] init]; printf("init: %d\n",[obj retainCount]); [obj retain]; printf("retain: %d\n",[obj retainCount]); [obj retain]; printf("retain: %d\n",[obj retainCount]); [obj release]; printf("release: %d\n",[obj retainCount]); [obj release]; printf("release: %d\n",[obj retainCount]); [obj release]; /* 実行するとエラーになるはずなのだが・・・ */ printf("release: %d\n",[obj retainCount]); [pool drain]; return 0; }
init: 1 retain: 2 retain: 3 release: 2 release: 1 release: 1
#import <Foundation/Foundation.h>
int main(void){
int prefixNumber = 0;
int i,j,temp;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *addressString = [NSString string];
//NSString *subnetString = @"255.255.255.0";
NSString *subnetString = @"255.255.255.240";
//NSString *subnetString = @"128.0.0.0";
//NSString *subnetString = @"255.248.0.0";
NSArray *subnetStringItems = [subnetString componentsSeparatedByString:@"."];
for(i = 0; i < 4; i++){
temp = [[subnetStringItems objectAtIndex:i] intValue];
for(j=0;j<8;j++){
prefixNumber += (temp & 1);
temp >>= 1;
}
}
NSLog(@"prefixNumber=%d",prefixNumber);
for(i = 0; i < 4; i++){
if(prefixNumber >= 8){
addressString = [addressString stringByAppendingString: @"255"];
prefixNumber = prefixNumber - 8;
}else if(prefixNumber > 0){
temp = 0;
temp = 255 - ((1 << (8-prefixNumber)) - 1);
addressString = [addressString stringByAppendingString: [ NSString stringWithFormat : @"%d", temp ]];
prefixNumber = 0;
}else{
addressString = [addressString stringByAppendingString: @"0"];
}
if(i<3){
addressString = [addressString stringByAppendingString: @"."];
}
}
NSLog(@"addressString=%@",addressString);
[pool drain];
return 0;
}
sudo port install ghc